package ru.vsu.amm.fuzzy;

import java.util.Arrays;

/**
 * Свёртки.
 * @author Иванов Илья
 * @since 03 января 2013
 *
 */
public class Convolutions {
	
	public static double additive(double[] weights, double[] scores) {
		if (weights == null || scores == null || weights.length != scores.length)
			throw new RuntimeException("Некорректные аргументы аддитивной свёртки");
		
		double convolution = 0;
		for (int i = 0; i < scores.length; i++)
			convolution += weights[i] * scores[i];
		
		return convolution;
	}
	
	public static double OWA(double[] weights, double[] scores) {
		if (weights == null || scores == null || weights.length != scores.length)
			throw new RuntimeException("Некорректные аргументы OWA-оператора");
		
		double OWA = 0;
		double[] ascending = Arrays.copyOf(scores, scores.length);
		Arrays.sort(ascending);
		for (int i = 0; i < ascending.length; i++)
			OWA += weights[i] * ascending[ascending.length - i - 1];
		
		return OWA;
	}
}